package com.xxx.rabbit;

import com.xxx.common.constant.RabbitConstants;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author Flying
 * @Description
 * @date 16:40 2018-10-25
 **/
@Configuration
@ConditionalOnProperty(prefix = "rabbitmq",value = {"enable"},havingValue = "true")
public class RabbitConfig {


    /**
     * description: 退款声明交互器
     * @author: Flying
     * @date: 2018-10-25 16:26
     * @params:
     * @return
     */
    @Bean
    TopicExchange topicExchange() {
        return new TopicExchange(RabbitConstants.REFUND_EXCHANGE);
    }

    //////////////退款/////////////////////
    /**
     * description: 退款声明队列
     * @author: Flying
     * @date: 2018-10-25 16:26
     * @params:
     * @return
     */
    @Bean
    public Queue refundQueue() {
        // true表示持久化该队列
        return new Queue(RabbitConstants.REFUND_QUEUE, true);
    }

    /**
     * description: 退款绑定
     * @author: Flying
     * @date: 2018-10-25 16:26
     * @params:
     * @return
     */
    @Bean
    public Binding bindingRefundQueue() {
        return BindingBuilder.bind(refundQueue()).to(topicExchange()).with(RabbitConstants.REFUND_KEY);
    }
    //////////////退款/////////////////////

    //////////////拍卖结束/////////////////////
    /**
     * description: 拍卖结束声明交互器
     * @author: Flying
     * @date: 2018-10-25 16:26
     * @params:
     * @return
     */
    @Bean
    TopicExchange topicFinishReserveExchange() {
        return new TopicExchange(RabbitConstants.FINISH_RESERVE_EXCHANGE);
    }
    /**
     * description: 拍卖结束声明队列
     * @author: Flying
     * @date: 2018-10-25 16:26
     * @params:
     * @return
     */
    @Bean
    public Queue finishReserveQueue() {
        // true表示持久化该队列
        return new Queue(RabbitConstants.FINISH_RESERVE_QUEUE, true);
    }

    /**
     * description: 拍卖结束绑定
     * @author: Flying
     * @date: 2018-10-25 16:26
     * @params:
     * @return
     */
    @Bean
    public Binding bindingfinishReserveQueue() {

        return BindingBuilder.bind(finishReserveQueue()).to(topicFinishReserveExchange()).with(RabbitConstants.FINISH_RESERVE_KEY);
    }
    //////////////退款/////////////////////






}
